import { requestClient } from '#/api/request';

export namespace FreelancerApi {
  /** 自由职业者列表查询参数 */
  export interface FreelancerListParams {
    page?: number;
    per_page?: number;
    name?: string;
    phone?: string;
    id_card?: string;
    status?: 'active' | 'inactive';
    sort_by?: string;
    sort_order?: 'asc' | 'desc';
  }

  /** 自由职业者记录接口 */
  export interface FreelancerRecord {
    id: number;
    name: string;
    phone: string;
    email: string;
    id_card: string;
    bank_account?: string;
    bank_name?: string;
    gender?: 'male' | 'female';
    education?: 'junior_high' | 'high_school' | 'college' | 'bachelor' | 'master' | 'doctor';
    age?: number;
    resume?: string;
    status: 'active' | 'inactive';
    task_names?: string[];
    status_label?: string;
    verification_status?: string;
    verification_status_label?: string;
    created_at: string;
    updated_at: string;
  }

  /** 分页响应结构 */
  export interface FreelancerListResponse {
    data: FreelancerRecord[];
    current_page: number;
    per_page: number;
    total: number;
    last_page: number;
    from?: number;
    to?: number;
    first_page_url?: string;
    last_page_url?: string;
    next_page_url?: string;
    prev_page_url?: string;
    path?: string;
    links?: any[];
  }
}

/**
 * 获取自由职业者列表
 */
export async function getFreelancerListApi(params: FreelancerApi.FreelancerListParams) {
  return requestClient.get<FreelancerApi.FreelancerListResponse>('/api/admin/freelancers', {
    params,
  });
}

/**
 * 获取自由职业者详情
 */
export async function getFreelancerDetailApi(id: string) {
  return requestClient.get<FreelancerApi.FreelancerRecord>(`/api/admin/freelancers/${id}`);
}

/**
 * 创建自由职业者
 */
export async function createFreelancerApi(data: Partial<FreelancerApi.FreelancerRecord>) {
  return requestClient.post<FreelancerApi.FreelancerRecord>('/api/admin/freelancers', data);
}

/**
 * 更新自由职业者
 */
export async function updateFreelancerApi(id: string, data: Partial<FreelancerApi.FreelancerRecord>) {
  return requestClient.put<FreelancerApi.FreelancerRecord>(`/api/admin/freelancers/${id}`, data);
}

/**
 * 删除自由职业者
 */
export async function batchActionFreelancerApi(data: { action: string; ids: number[] }) {
  return requestClient.post<null>('/api/admin/freelancers/batch-action', data);
}
